<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方法与事件处理器</title>
</head>
<body>
<div id="example">
    <input type="button" @click="greet('hi!', $event)" value="Greet"><br>
    <!-- 事件修饰符-->
    <a v-on:click.stop="doThis">阻止单击事件冒泡</a><br>
    <a @click.stop.prevent="doThat">修饰符可以串联</a><br>
    <form v-on:submit.stop.prevent="onSubmit">提交事件不再重载页面</form>
    <form v-on:submit.prevent>只有修饰符</form>
    <!-- 1.0.16新增修饰符-->
    <div v-on:click.capture="doThis">添加事件侦听器时使用 capture 模式</div>
    <div @click.self="doThat">只有当事件在该元素本身触发时（而不是子元素）触发回调</div>
    <!-- 按键修饰符-->
    <input v-on:keyup.13="submit" value="只有在keyCode是13时调用vm.submit()">
    <!-- 常用按键别名：enter，esc,space,left,right,tap,delete,up,down-->
    <div @keyup.enter="submit"></div>
    <!-- 1.0.18支持单字母按键别名-->
    <div @keyup.a="submit"></div>
    <!-- 自定义按键别名-->
    <div></div>
</div>
<script src="../js/libs/vue.js"></script>
<script>
    var fn = new Vue({
        el: '#example',
        data: {
            name: 'Lee'
        },
        methods: {
            greet: function (msg, event) {
                console.log(msg + this.name);
                //event是原生DOM事件
                console.log(event.target.tagName);
            },
            doThis: function () {
                top.location = 'http://www.baidu.com';
            },
            doThat: function () {
            },
            onSubmit: function () {
            },
            submit: function () {
            }
        }
    });
    Vue.directive('on').keyCodes.f1 = 112;
//    fn.greet();
</script>
</body>
</html>